/**
* File:ShutDownWindows.h 
* It provides a class to shutdown, logoff or reboot Windows.
*
* Copyright (c) 2008, J PENG
* All rights reserved.
**/

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


namespace PJJTimer {

	/// <summary>
	/// Summary for ShutDownWindows
	///
	/// The class that perform user definition to shutdown, logoff or reboot Windows.
	/// There will be a certain countdown time to remind the user before taking action.
	/// </summary>
	public ref class ShutDownWindows : public System::Windows::Forms::Form
	{
	public:
		ShutDownWindows(int action)
		{
			InitializeComponent();
			process->StartInfo->FileName = System::Environment::SystemDirectory + L"\\shutdown.exe";
			shutTime = 30;
			seconds->Text = shutTime.ToString();
			alarmOnAction = action;
			UpdateFormInfo();
			if(language != Languages::English) SetLanguages();

			timer->Start();
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~ShutDownWindows()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::PictureBox^  imageBox;
	private: System::Windows::Forms::Label^  label_ActionInfo;
	private: System::Windows::Forms::Label^  seconds;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Button^  button_Cancel;
	private: System::Windows::Forms::Button^  button_OK;
	private: System::Windows::Forms::Timer^  timer;
	private: System::ComponentModel::IContainer^  components;
	private: System::Diagnostics::Process^  process;

	private:
		int shutTime; //The value indicates how long to wait before taking action
		int alarmOnAction;


#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->components = (gcnew System::ComponentModel::Container());
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(ShutDownWindows::typeid));
			this->imageBox = (gcnew System::Windows::Forms::PictureBox());
			this->label_ActionInfo = (gcnew System::Windows::Forms::Label());
			this->seconds = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->button_Cancel = (gcnew System::Windows::Forms::Button());
			this->button_OK = (gcnew System::Windows::Forms::Button());
			this->timer = (gcnew System::Windows::Forms::Timer(this->components));
			this->process = (gcnew System::Diagnostics::Process());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imageBox))->BeginInit();
			this->SuspendLayout();
			// 
			// imageBox
			// 
			this->imageBox->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"imageBox.Image")));
			this->imageBox->Location = System::Drawing::Point(12, 100);
			this->imageBox->Name = L"imageBox";
			this->imageBox->Size = System::Drawing::Size(64, 64);
			this->imageBox->TabIndex = 0;
			this->imageBox->TabStop = false;
			// 
			// label_ActionInfo
			// 
			this->label_ActionInfo->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 16, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->label_ActionInfo->Location = System::Drawing::Point(3, 12);
			this->label_ActionInfo->Name = L"label_ActionInfo";
			this->label_ActionInfo->Size = System::Drawing::Size(330, 26);
			this->label_ActionInfo->TabIndex = 1;
			this->label_ActionInfo->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
			// 
			// seconds
			// 
			this->seconds->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
			this->seconds->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 24, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->seconds->ForeColor = System::Drawing::Color::Red;
			this->seconds->Location = System::Drawing::Point(130, 40);
			this->seconds->Name = L"seconds";
			this->seconds->Size = System::Drawing::Size(76, 36);
			this->seconds->TabIndex = 2;
			this->seconds->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
			// 
			// label2
			// 
			this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 16, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(134)));
			this->label2->Location = System::Drawing::Point(118, 77);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(100, 26);
			this->label2->TabIndex = 1;
			this->label2->Text = L"Seconds";
			this->label2->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
			// 
			// button_Cancel
			// 
			this->button_Cancel->DialogResult = System::Windows::Forms::DialogResult::Cancel;
			this->button_Cancel->Location = System::Drawing::Point(260, 139);
			this->button_Cancel->Name = L"button_Cancel";
			this->button_Cancel->Size = System::Drawing::Size(64, 25);
			this->button_Cancel->TabIndex = 3;
			this->button_Cancel->Text = L"Cancel";
			this->button_Cancel->UseVisualStyleBackColor = true;
			this->button_Cancel->Click += gcnew System::EventHandler(this, &ShutDownWindows::OnButtonCancelClick_Event);
			// 
			// button_OK
			// 
			this->button_OK->DialogResult = System::Windows::Forms::DialogResult::OK;
			this->button_OK->Location = System::Drawing::Point(190, 139);
			this->button_OK->Name = L"button_OK";
			this->button_OK->Size = System::Drawing::Size(64, 25);
			this->button_OK->TabIndex = 3;
			this->button_OK->Text = L"OK";
			this->button_OK->UseVisualStyleBackColor = true;
			this->button_OK->Click += gcnew System::EventHandler(this, &ShutDownWindows::OnButtonOKClick_Event);
			// 
			// timer
			// 
			this->timer->Interval = 1000;
			this->timer->Tick += gcnew System::EventHandler(this, &ShutDownWindows::OnTimerTick_Event);
			// 
			// process
			// 
			this->process->StartInfo->Arguments = L"-s -f -t 00";
			this->process->StartInfo->Domain = L"";
			this->process->StartInfo->LoadUserProfile = false;
			this->process->StartInfo->Password = nullptr;
			this->process->StartInfo->StandardErrorEncoding = nullptr;
			this->process->StartInfo->StandardOutputEncoding = nullptr;
			this->process->StartInfo->UserName = L"";
			this->process->SynchronizingObject = this;
			// 
			// ShutDownWindows
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->CancelButton = this->button_Cancel;
			this->ClientSize = System::Drawing::Size(336, 176);
			this->Controls->Add(this->button_OK);
			this->Controls->Add(this->button_Cancel);
			this->Controls->Add(this->seconds);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label_ActionInfo);
			this->Controls->Add(this->imageBox);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
			this->MaximizeBox = false;
			this->MinimizeBox = false;
			this->Name = L"ShutDownWindows";
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
			this->Text = L"Time Up Action..";
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->imageBox))->EndInit();
			this->ResumeLayout(false);

		}
#pragma endregion

	public:
		void SetLanguages();
	private:
		void TakeAction();
		//Update the information which displayed on the form according to the alarmOnAction
		void UpdateFormInfo();

		System::Void OnTimerTick_Event(System::Object^  sender, System::EventArgs^  e);
		System::Void OnButtonCancelClick_Event(System::Object^  sender, System::EventArgs^  e);
		System::Void OnButtonOKClick_Event(System::Object^  sender, System::EventArgs^  e);
};
}
